<!--{template /module/admin/view/head}-->
<div id="left_layout">
	<div id="main_content" class="container-fluid">
		<!--{template /module/admin/view/head_nav}-->
		<div class="row-fluid">
			<form method="post" action="{$ADMIN_SCRIPT}/admin/table/{$dispatches[method]}&id={$_var[gp_id]}&page={$_var[page]}&psize={$_var[psize]}" onsubmit="javascript:return check_form(this);">
			<input type="hidden" name="formsubmit" value="yes" />
			<div class="well widget">
				<div class="widget-header">
					<p class="text">* {lang admin.validate.require}</p>
				</div>
				
				<div class="widget-content">
				<fieldset>
					<label>{lang admin.table_edit.view.no.label} *</label>
					<input type="text" class="input-mini" name="txtDisplayOrder" placeholder="{lang admin.table_edit.view.no.placeholder}..." maxlength="3" value="{$table[DISPLAYORDER]}" /> 
					<span class="help-inline">{lang admin.table_edit.view.no.tips}</span>
					
					<label>{lang admin.table_edit.view.cname.label} *</label>
					<input type="text" class="input-large" name="txtCName" placeholder="{lang admin.table_edit.view.cname.placeholder}..." maxlength="50" value="{$table[CNAME]}" /> 
					<span class="help-inline">{lang admin.table_edit.view.cname.tips}</span>
					
					<label>{lang admin.table_edit.view.identity.label} *</label>
					<input type="text" class="input-large" name="txtIdentity" placeholder="{lang admin.table_edit.view.identity.placeholder}..." maxlength="30" value="{$table[IDENTITY]}" /> 
					<span class="help-inline">{lang admin.table_edit.view.identity.tips}</span>
					
					<label>{lang admin.table_edit.view.remark.label}</label>
					<textarea class="span6" rows="3" name="txtRemark">{$table[REMARK]}</textarea>
					<span class="help-inline">{lang admin.table_edit.view.remark.tips}</span>
					
					<label>{lang admin.table_edit.view.file.label}</label>
					<input type="text" class="input-mini" name="txtFileNum" maxlength="3" value="{$table[FILENUM]}" /> 
					<span class="help-inline">{lang admin.table_edit.view.file.tips}</span>
				</fieldset>
				
				<h4>{lang admin.table_edit.view.column.label}</h4>
				<hr/>
				<table class="table" style="width:850px;">
					<thead>
						<tr>
							<th width="60">{lang admin.table_edit.view.column.th.operate}</th>
				            <th width="80">{lang admin.table_edit.view.column.th.no}</th>
				            <th>{lang admin.table_edit.view.column.th.identity}</th>
				            <th>{lang admin.table_edit.view.column.th.cname}</th>
				            <th width="120">{lang admin.table_edit.view.column.th.type}</th>
				            <th width="80">{lang admin.table_edit.view.column.th.length}</th>
				            <th width="60"><!--{if $dispatches['method'] == '_update'}-->{lang admin.table_edit.view.column.th.lock}<!--{/if}--></th>
						</tr>
					</thead>
					<tbody id="tbl_body_column">
					<!--{loop $table[COLUMNS] $_loop $column}-->
			        <tr>
			        	<td>
			        		<a class="btn btn-mini btn-primary" href="javascript:void(null);">{lang admin.operation.delete}</a>
			            </td>
			             <td>
			                <input type="text" class="input-mini" name="displayorder[]" value="{$column[displayorder]}" />
			            </td>
			            <td>
			                <input type="text" class="input-medium" name="identity[]" maxlength="25" value="{$column[identity]}" />
			            </td>
			            <td>
			                <input type="text" class="input" name="name[]" maxlength="15" value="{$column[name]}" />
			            </td>
			            <td>
			                <select name="type[]">
			                	<option value="tinyint" {if $column['type'] == 'tinyint'}selected="selected"{/if}>{lang admin.table_edit.view.column.type.tinyint}</option>
			                	<option value="int" {if $column['type'] == 'int'}selected="selected"{/if}>{lang admin.table_edit.view.column.type.int}</option>
			                	<option value="decimal" {if $column['type'] == 'decimal'}selected="selected"{/if}>{lang admin.table_edit.view.column.type.decimal}</option>
			                	<option value="varchar" {if $column['type'] == 'varchar'}selected="selected"{/if}>{lang admin.table_edit.view.column.type.varchar}</option>
			                	<option value="datetime" {if $column['type'] == 'datetime'}selected="selected"{/if}>{lang admin.table_edit.view.column.type.datetime}</option>
			                	<option value="text" {if $column['type'] == 'text'}selected="selected"{/if}>{lang admin.table_edit.view.column.type.text}</option>
			                </select>
			            </td>
			            <td>
			                <input type="text" class="input-mini" name="length[]" value="{$column[length]}" />
			            </td>
			            <td>
			            	<select name="locked[]">
			            		<option value="1" {if $column['locked'] == 1}selected="selected"{/if}>{lang admin.table_edit.view.column.lock.enable}</option>
			            		<option value="0" {if $column['locked'] == 0}selected="selected"{/if}>{lang admin.table_edit.view.column.lock.disenable}</option>
			            	</select>
			            </td>
			        </tr>
			        <!--{/loop}-->
			        <tr>
			        	<td>
			        		{lang admin.operation.add}
			            </td>
			             <td>
			                <input type="text" class="input-mini" name="displayorder[]" value="" />
			            </td>
			            <td>
			                <input type="text" class="input-medium" name="identity[]" maxlength="25" value="" />
			            </td>
			            <td>
			                <input type="text" class="input" name="name[]" maxlength="15" value="" />
			            </td>
			            <td>
			                 <select name="type[]" style="width:80px;">
			                 	<option value="tinyint" selected="selected">{lang admin.table_edit.view.column.type.tinyint}</option>
			                	<option value="int">{lang admin.table_edit.view.column.type.int}</option>
			                	<option value="decimal">{lang admin.table_edit.view.column.type.decimal}</option>
			                	<option value="varchar">{lang admin.table_edit.view.column.type.varchar}</option>
			                	<option value="datetime">{lang admin.table_edit.view.column.type.datetime}</option>
			                	<option value="text">{lang admin.table_edit.view.column.type.text}</option>
			                </select>
			            </td>
			            <td>
			                <input type="text" class="input-mini" size="8" name="length[]" value="" />
			            </td>
			            <td></td>
			        </tr>
			        <tr>
			            <td colspan="7">
			            <input type="button" id="btn_add_column" name="btnAddColumn" class="btn" value="{lang admin.table_edit.view.column.quick}" />
			            </td>
			        </tr>
			        </tbody>
				</table>
				</div>
				
				<h4>{lang admin.table_edit.view.join}</h4>
				<hr/>
				<fieldset id="join_tables">
					<!--{loop $join_tables $item}-->
					<label class="checkbox inline">
					<input type="checkbox" class="fancy" name="jointables[{$item[IDENTITY]}]" value="1" ref="{$item['IDENTITY']}" {if $table['JOINS'][$item['IDENTITY']]}checked="checked"{/if} />{$item[CNAME]}
					</label>
					<!--{/loop}-->
					<br class="clear"/>
					
					<hr />
					<!--{if $dispatches['method'] == '_add'}-->
					<button type="submit" class="btn btn-small btn-primary" {$dispatches[operations][add]}>{lang admin.operation.submit}</button>
					<!--{elseif $dispatches['method'] == '_update'}-->
					<button type="submit" class="btn btn-small btn-primary" {$dispatches[operations][edit]}>{lang admin.operation.submit}</button>
					<!--{/if}-->
					<button type="reset" class="btn btn-small">{lang admin.operation.reset}</button>
					<button type="button" class="btn btn-small" onclick="javascript:location.href='{$ADMIN_SCRIPT}/admin/table&page={$_var[page]}&psize={$_var[psize]}';">{lang admin.operation.go.back}</button>
				</fieldset>
			</div>
			</form>
		</div>
	</div>
</div>

<script>
function check_form(frm){
    if(frm.txtDisplayOrder.value.trim().length == 0){
    	$(frm.txtDisplayOrder).next('.help-inline').css('color', 'red');
    	frm.txtDisplayOrder.focus();
    	return false;
    }
    
    if(!frm.txtDisplayOrder.value.trim().isInt()){
    	$(frm.txtDisplayOrder).next('.help-inline').css('color', 'red');
    	frm.txtDisplayOrder.focus();
    	return false;
    }
    
    if(frm.txtCName.value.trim().length == 0){
    	$(frm.txtCName).next('.help-inline').css('color', 'red');
    	frm.txtCName.focus();
    	return false;
    }
    
    if(frm.txtIdentity.value.trim().length == 0){
    	$(frm.txtIdentity).next('.help-inline').css('color', 'red');
    	frm.txtIdentity.focus();
    	return false;
    }
    
    return true;
}

$(function(){
	$('.fancy').uniform();
	
	$('fieldset input,textarea,select').blur(function(){
		$(this).next('.help-inline').css('color', '#333');
	});
	
	$('#btn_add_column').click(function(){
    	var tbody = $('#tbl_body_column').get(0);
    	var tempInsertRow = tbody.rows[tbody.rows.length - 2];
    	var tempNewRow = tempInsertRow.cloneNode(true);
    	tempNewRow.style.display = '';
    	
    	var inputs = tempNewRow.getElementsByTagName('input');
    	for(var i = 0; i < inputs.length; i++){
    		if(inputs[i].name.indexOf('name') != -1 
    		|| inputs[i].name.indexOf('displayorder') != -1 
    		|| inputs[i].name.indexOf('identity') != -1 
    		|| inputs[i].name.indexOf('length') != -1) inputs[i].value = '';
    	}
    	
    	tbody.insertBefore(tempNewRow, tbody.rows[tbody.rows.length - 1]);
    });
	
	$('#tbl_body_column .btn-primary').click(function(){
		$(this).parent().parent().remove();
	});
});
</script>

<!--{template /module/admin/view/foot}-->